<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script src="<?=Q::ini('custom_system/base_url');?>js/validator.js"></script>
<script type="text/javascript">
$(function(){
	$(".info").colorbox({width: "40%", height: "60%", iframe: true});
	$("#dialog_shop").dialog({autoOpen: false, modal: true, height: 200, width: 600,buttons: {
        '授权': function() {
            $('form').submit();
        },
    }});
	$(".auth_shop").click(function(){
		var shop_id = $(this).attr('shop_id');
		$("#shop_id").val(shop_id);
		$("#dialog_shop").dialog("open");
	});
});
</script>
<table class="list_table" width="100%">
<tr>
	<th>店铺</th>
	<th>Client Id</th>
	<th>Client Secret</th>
	<th>Access Token</th>
	<th>Refresh Token</th>
	<th>授权过期</th>
	<th>更新时间</th>
	<th>跳转链接</th>
	<th>操作</th>
</tr>
<?foreach ($shop as $s):?>
<tr>
	<td><?=$s['name']?></td>
	<td><?=$s['client_id']?></td>
	<td><?=$s['client_secret']?></td>
	<td><?=$s['access_token']?></td>
	<td><?=$s['refresh_token']?></td>
	<td><?=$s['expired_time']?></td>
	<td><?=$s['last_refresh_time']?></td>
	<td><?=$s['redirect_uri']?></td>
	<td>
		<a href="<?php echo url('Setting::Basic/WishShopEdit', array('id' => $s['id'], 'shopname' => $s['name']))?>" class="info">填写应用信息</a>
		<a target="_blank" href="https://sandbox.merchant.wish.com/oauth/authorize?client_id=<?php echo $s['client_id']?>">跳转wish登录</a>
		<a href="javascript:viod(0);" class="auth_shop" shop_id="<?php echo $s['id']?>" >授权</a>
	</td>
</tr>
<?endforeach;?>
</table>
<div id="dialog_shop" title="授权新店铺">
<form action="<?=url('Setting::Basic/WishShopAuth')?>" method="post" onSubmit="return Validator.Validate(this,3)">
<input type="hidden" name="id" id="shop_id" />
<table class="form_table">
<tr>
	<th>authorization_code（跳转Wish登录后URL获得）</th>
	<td><input type="text" name="code" dataType="Custom" regexp="^(\S)" msg="授权码不能为空"/> <span class="red">*</span> </td>
</tr>
</table>
</form>
</div>
<?php $this->_endblock();?>